rearranged javascript