Issue 4 - refactor in prep for pulling out into npm package