reordered key check statements in timer function