Speed improvements, removing unnecessary operations and performing multiplications instead of divisions