Add debug logging code from earlier post