added avg color function. check for errors