Moar refactoring, I really need squash all these global variables