Introduce #extract_with_name method, fixes the code duplication