Fixup some missing and/or incorrect variables
Move trigonometric funcs to a module