simplify javascript, refactor