Optimzed some code