Issue 4

Fixes #4 for Firefox. Includes numerous tidying up along the way.