begin to optimize codes