Cleaned up some code and fixed some bugs that were left over from adding
the database query functionality