fixing bug in resolving next node logic and removing unneeded code