Fixed db bugs