Moved bin functionality into lib. Added mocha tests.