Fixed search off-by-one error