Refactor buffer drawing into subfunctions