refactored code, now no external call to piglow