Rewriting javascript so that there are not dependency problems