Fix authorization and authentication bugs