changed several queries to raw sql