Removed unnecessary operations, consolidated some operations to outside for loops, changed floor+1 to ceil.