Fixes some database bugs