Added tests, removed bugs.