cleanup and rename globals