JS refactor and design tweak