Bug with deleting port too early fixed