Fixed potential nil-pointer exception