Moved functions outside of document.ready.