database code cleanup