rewritten for npm/browserify, integrate with threepointone/fn