Optimized some graphics code