Fix for NUCRDBMS-808, NUCRDBMS-809 and implementation for NUCRDBMS-810

Sorry for 3 issues at one pull request, but github has no support for one commit pull requests. This changes proven in production with version 3.2 (1.5 years) and 4.0 (about half of month).