fixed the setTimeout issue