Major code cleanup in graphics section