Move some code from global functions to Light class.