move query creation to models