updated cleanup functions and unit tests