Unit tests and cleanup