Added Rich's example code
Implemented runtime type detection