SOAP-1796 Fixed concurrency issue and some code cleanup