Fixed a few bugs and remoed console.log calls.
Added tests, and fixed bugs.