insert setTimeout to avoid race conditions