Duplication refactoring

Hi there,

I refactored the code to be more generalized to get rid of the duplication.  Hope that it's helpful!  Thanks for writing this example wrapper!

Cheers,
Rob