Changed hardcoded SQL to query object