Fixed bug because of use of Math.ceil on negative numbers.