Code cleanup and properly working async functions