Fixed a null-ref bug