Major refactoring of API