Fixed issue with local vs global vars