Fix possible NPE.
Merge changes from 1.0.x SVN.
Fix for bug 1109 and merge other changes from 1.0.x SVN.