Implemented the math