Fixed offset by one bug