changing selected_port to local variable