javascript refactor and updates