Added tests and cleanups.