Changed code so use of global is not required.