changed a few variables to global