Improved code folding detection