Moving function outside .ready