Added additional conditional check to line 147 to prevent PHP notice