refactored search into more composable functions