Tidy up code
Inline #build_query