several lines of ugly code added to solve lightning issues