fixed an off-by-1 and updated comments