Merged Amol's fix for getattr