Fixed empty database bugs