Revert "Refactored querying the database a bit"

This reverts commit 23a520df74c72e656216c1462516c15a522cbfb9.