Fixed database bugs