use getattr instead of duplicate code