Refactored search from horrible to decent