Moved getLocalEP to its own function