refactored code for serving and processing search form