Refactored if statements in the onMessage listener

I changed the if change for a single switch..case.
The code looks more cleaner now and feels faster.
It needs extensive testing, through I checked out
the main functions something could have scaped my tests
specially, the bookmarks.