Added isAuthorized and bug-tested