Move color extraction into separate function