Rearranged javascript