All seems to work, just added some comments and a bit of line spacing.\nDuplicated logs seems to be an artifact of how the hosts are communicating, rather than any error in the code.