refactor and better authentication