Api refactoring bug fixes