update alternating logic with comments.