refined api interaction, added error messages, maintains login state