fixed an off-by-one bug