mastere -> dev merge and a fix

Fixes a runtime in lgihting code
http://pastebin.com/WwM5qZZ1