Add timelimit for infinite loop