#63 cherry picked contributions and added null check

fixes #63