Refactor implementation; Unit tests
Merge pull request #1 from ptseng/proxy-support

@ptseng. Thank you. This looks good and has been tested successfully here.