Better current page detection

See #166, #306, #108