Converted global variables to procedures