deal with setTimeout properly