KER-258: Fixed bugs met during the integration tests and improved the code