Fixing null ref bug