building raw query and replacing cursor, maybe...