Finalized version with unit tests and links to JSFiddles