changed order of operations

(cherry picked from commit 09f40255d689f2b5dd4533c0552ae72861109d76)