Fix null pointer exception when using uninitialized r