Fixed argument checks, now NULL pointer are no longer dereferenced
in functions.