Updated for better browser compatibility