Some refactorings
Cleaned up some external IP/port calculations
Some refactorings