greatly cleaned up globals