refactoring, add comments and javascript refactoring