The code needs significant unit test coverage. gcov or similar coverage tools should show complete coverage of the code paths.