improved timer logic