Some refactoring to use async.