minor changes of code arrangement