Refactored into new files. Added tangent calculations.