code optimization and restructuring