authorize context refactoring and bug fixing
small fixes