apply patch sent by Ilya Golshtein