Final version with logging and highest sum of nodes