Updated for improved code clarity
Much improved - and dynamic - brightness control