Made brightness vs distance only take into account brightest half of pixels. Tidied up code a bit.