homework1 code optimize