Some variables were global when they should not have been