Refactored graphics code