[FE] mark visited nodes
[BE] small improvements to algorithms