Tweaked for better cross-browser compatibility