Extended the example and added more debug output