move database access to a separate module