Improve opening/closing language logic