Added search feature. Decomposed more and cleaned some code.