Modified Math.round to Math.floor to be more compatibile with original code
Reformatted code