refactoring some js
more refactoring