refactored some js