Fix bugs in master

Ping @msmith-techempower and @aschneider-techempower for a code review before these changes are merged. I updated your port closing function quite a bit and fixed bugs that were preventing master from running properly. If this looks good it's ready to merge, but given how close you are to R10 I want someone to eyeball it before it hits master
@hamiltont This is still broken on my systems: https://gist.github.com/msmith-techempower/41583b89a083d361a62f