Rearrange script functions within document ready