Partial fix for bug#4465. WIP.