Nullreference bug fix