added better luminance calculation, fixed bugs