Fix off by 1 use Math.floor for everything for clarity