Fix overlapping detection. Fix an use after free. Fixes #41