Improvements and bug fixes

- fixed the SSH hang bug
- added the `keep_instance` config parameter
- fixed infinite loop while trying to find a port for the HTTP server, and all of them were unavailable