merges Sergey's patch