Restructuring the code & adding the port argument