Misc fixes

A number of various fixes that the upcoming Sockets layer depends on