refactor the implementation of ports, need further refactor