Bugfixes regarding queries on empty db and deletion of records