Performance: avoid calling ifloor where possible, add @inbounds in a couple places