js callback and timeout handling