now works for three nodes