Database query changes

This should be everything.