Added tests, some fixes.