Search changes

Fixed error in search, some refactoring