Implemented some db functionality