Functional but messy search clear implementation.