fixed and refactored some js