cleanup database code