Refactoring. Better errors. Moving code to use async versions