changed order of some code