Cleanup, compacting and optimization part.1