Grain engineering: How nanoscale inhomogeneities can control charge collection in solar cells