Rearrange javascript