cleanup and extraction of functionality