Fixing nil checks and casting of primtive types.