Refactored the implementation of the first exercise. (used double precision because of accuracy)