This is first step of refactoring. Next steps follow with possibly a query builder, or atleast using some reusable methods.