Fixed a bug that could cause an NPE exception.