rearrange some code
merge