Refactor Database context related stuff