Updated to not use any Global variables.