Added conditional to resolve Undefined Variable error.