fix some db bugs