Bug: didn't take into acount negative numbers, solved using Math.abs