merge two parts of similar codes to a method
Merge remote-tracking branch 'origin/wmy_local'