initial version branched from http://hanno-rein.de/archives/349