Implementing the core search algorithm