Added more debugging and a bit more cleanup.