check if data exists before accessing a property of it