slightly refactor js