Fixes for NH-3480 and NH-3453

@hazzik, I have rebased the previous pull request (#211) for these issues.