rearranged javascript controllers and code