Move port splitting to its own function