Added tests and cleanup changes