This is a rework of PR#24 based on review comments. The rework mostly involved moving changes to the proper files, aligning with upstream Go src/net file layout.