Cleaned up code. fixed bug in :ref: / :chap: div.