moved sql statement to factory