database code mostly finished

few other changes here and there