Replaced hasattr with getattr