Patch contributed by Carsten Guenther <cguenther@gmail.com>.