Finished changes to add gamma correction and some various cleanup.