Add more guards for weird cases; Add more unit tests and sql coverage tests