Added loads of debug logging to see what is happening