implement total count query
clean up second stage of insertion more
implement remaining queries