Using more defensive programming to avoid NPE. #184