Currently, some rule checks are integrated into the stack cleanup
process, resulting in some obfuscated-looking behaviour.
This moves the stack cleanup to the very end, once all operations
have completed, including nullfail and the dummy element check.
Depends on D3673