Moved address formatting logic to separate function

As per PR #285 the address formatting logic has been moved to a separate function to simplify testing and allow for the logic to be easily used by 3rd party code.