refactoring 1-d search