Refactored environment discovery.  Still need to assign and rank port preference.