Merge Pavel's changes into 3.1 branch of my repo