Move db handling to separate class