fixed mistake in next_integer function