Various api changes; code refactoring