Fixed a null ref exception bug