These loops were skipping over the top stack entry, and there's already a function that does this correctly.