fixed bugs when DB is empty