Refactor authenticator.js