Changed float to double and refactored most of the code