added a guard clause to prevent fatal php errors