move database construction out of UI