Code style.
Optimize simple pop.
Check closed state in the loop.