Patch contributed by Kris Rietveld (kris@imendio.com)