Some refactoring and clean up of async code