Fix function that retrieves the next dirty node

1. Get the correct next graphnode for both normal run and delta run
2. Added simple testcase for function redefinition