CRA-704

 Memory leaks and bug fixes, test cases 1 - 3