Refactor template and front end js