refactored some js-code