Fixed a null reference bug