Remove globals, use pointers, cleanup