Additional fix for JENKINS-20767

This Pull Request contains more fixes for JENKINS-20767.

See comments here:
https://issues.jenkins-ci.org/browse/JENKINS-20767?focusedCommentId=198491&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-198491