Fixed calling a method on an undef variable