Fixed some bugs due to asynchronicity