refactoring some js