Refactoring the code to use the new API