database stuff mostly done