Refactor gfx. r? @metajack

This patch refactors gfx some.