Refactor input/output infrastructure to use ports.