some changes by Sergey Zhidkov