some refactoring and fix typo in CTPORT