refactor js a bit