Refactor, move SQL queries to models