#63 cherry picked contributions and added null check