Use first heading even if there is a line of code first

See issue #265.
Fix typo
Handle case where no sections are available
Merge pull request #266 from mbuettner/master

Use first heading even if there is a line of code first