Add tests and cleanup