Fixed a NullPointerException in rare cases.