As this setTimeout is duplicated above could you extract it to a separate function?