rearrange things, fix compile error