Merge branch 'fix-stack-overflow' into 'master'

Fix some stack overflows caused by recursion with identical arguments/state.

See merge request !5
6 jobs for master in 6 minutes and 56 seconds (queued for 1 second)