More refinement, including changing types to typedefs where appropriate. Added cmath functions needed. Still some Chris TODOs near end.