Cleanup, compacting and optimization part.2.1