optimize code structure phase 2