added debug logging to most things