2287: code arrangement

refactor and arrange source code