Some tweaks to transport layer

refactored function with multi-return semantics