Complete rewrite for crossbrowsing support