Improved clarity, fixed off-by-one error