App factory

Fixes #2 by breaking all state logic out of the extension scope and on to the application.