made some changed to optimize code