Changed to clearner solution proposed by @limhoff-r7.