Split debugging

As #28 but with some additional commits to improve debug.log logging.