Added tests and cleanup