Improve browser detection algorithm and fix some issues