cleaned and commented database code