search-engine: incorporated most of ayust's suggestions

Lots of things that make the code better here!