Bug Fixes to db query
Fixes some edge cases
Merge pull request #60 from Kdr18702/TestingDB

Bug Fixes to db query