Rearranged Javascript