Updated script to be run in .ready() function