API improvements, refactoring