Added search model and modularized code slightly