Fixing code as per suggestions on PR 771.