Fixed null ref bug