Working log in/out + refactored