picking nits here, but maybe use `NULL` instead of `0`, especially since you're explicitly checking for `NULL` in the rest of this code.