Move DB code into a separate module