Added flag to easily switch between running in browser and running as extension. Cleaned up code a bit.