fixed a bug which would crash the server if db is empty