Major refactoring for better async