Improve extraction algorithm