Code from Tang Lee. Separate .h and .cpp from original code. Delete Chinese annotations, which will be translated to English and added again later.