a tiny bit of clean-up and added lots of logging to help me understand the flow of events