Implemented CleanupScript and added more unit tests