moved some queries to direct SQL calls, more testing