rewritten for npm/browserify