Reimplemented closure guards

Reimplemented the guards that check whether the same function is being called again in a trace, instead of a different function.