Moved the check_null() to a separate util.h as inline function.
Added more code. Fixed bugs. segfault error went away.