A new trial to solve the problems described in JIRA COCOON-1939. There might still be some other problems with the code, so it need a more thorough review.