code cleanup
optimizes code by removing while loop
removes floating point exception error