Cleanup, compacting and optimization part.1.4