Fixed asynchronous JS bug