Fixed operations on port

Setting port didn't work. Fixed it, added some tests.