Use hasattr instead of direct attribute access