Improve behaviour of open-line substitute function