changed brightness calculation
added more comments
changed colour average algorithm to have a second tolerance
packed algorithm into its own function