Moved functions outside document.ready