[FIX] Check if object is valid before trying to access it