Avoid getting non-existing array items. Use reference to array items instead of pointers where it is possible. Create test case. Before the fix this test raised exception in debug mode.