Got the functionality to email query results to a user mostly working, but there seems to be some performance problems.