Reworked so that it works better with browserify