Submitted by Nikolay Sturm <sturm@sec.informatik.tu-darmstadt.de>. Thanks to Aleksander Piotrowski for sending patches.