refactored to floats and fixed infinite loop bug