cleaned up unneccessary global variables and made most local