refactor codes and applied comments