Structural changes, GLOBALS, some function fixes