added error handling, added the rest of the trig functions and ran calulations on a sepreate thread to prevent crashing due to the ui thread being blocked.