improved by mvidner suggestion