fixing asynchronous problem