added login mechanic and error handling