Merge api refactoring and exception refactoring