defer js, authenticate refactor