Fix to the cleanup logic flow to ensure the last connection success to fire is cleaned up. Specific fix for the port test functionality.

Also auto formatted the class.