Add tests and fix null case