redid log in/out logic with errors and better redirects