(hopefully) optimized calculate_color