Changed test framework to nodeunit and did some refactoring