Refactor db context