Revised A* to handle any formation of nodes