Fix compiler warnings.
Added missing NULL-pointer checks.
Use custom assertion checks.