refactoring of lighting code