Several fixes

fixes https://issues.jenkins-ci.org/browse/JENKINS-23483 and https://issues.jenkins-ci.org/browse/JENKINS-18110
Oh, yes, indeed. Didn't check this, sry