Fixed JavaScript asynchronous issue