polish code

make some code more elegant