[#2 - xuehai] - refactored the code