divided code into functions and made content script use a state machine
Added more extensible header collection