Patch by Anders Carlsson <andersca@mac.com>