The various edge case exit paths here, and ways you ignore error cases in some case, is worth documenting.  Put a comment  over this explaining the various paths and what's possible.