Fix node indexes

This is an update to #595, but sent from its own branch.