refactoring and adding javascript document auto-completion