Mini rewrite of background.js

Lot's of debug still.