add timer for max time, but there are still some bugs need to be fixed