Refactor ports and messaging