fixed JS timing bug