refactored portsx.rb for lesser complexity