Code cleanup

Removed console.log calls.
Inverted a few ifs to fail fast.
Method to discover initial page (to avoid ugly ifs).