Extract part of logic from #4 to separated function