Fixing off-by-one error