Merged bug-fix for off-by-one bug