refactor controller to place logic to query db in model