`<p><a><b><p>` [is parsed](http://bit.ly/Qy5kpd) as `<p><a><b></b></a></p><p></p>`, so not only the top of the stack should be checked. This is where things start to become messy, as `li`s only close `li`s that don't have a `ul` in front of them.