Fixed bug with clean_main, fixed issue with finding inactive ports, and removed accidental test code.