Cleanup and optimalization