refactor js and templates