NullReferenceException bugfix