code refactoring for new API