Ensures termination of inner while loop and cleans up #map.
* Tested working against ubuntu target using the sshexec test script.
Land @jvennix-r7 changes