added debugging messages in multiple places