Port fixes

First of all, thanks for this.

I had to make these changes to get things working.