Added tests and fixes.