Fixed NULL pointer checks and compile errors.