Replace hasattr with getattr