Added stuff for ports and reading and writing from threads