optimize code #2