timer_select.patch by Moritz Venn, with minor fixes