Moved extraction and extraction handling in separate functions