refactoring javascript parsing