refactoring with many changes and features to API