Refactor db a bit