Refactor: drawing to functional code