Fix NullPointerException in very rare cases