Algorithm works for single node