Fix and refactor the frame traversal logic.
Tweak comments.