Improve use of global vars