Moved some variables to a more global space and changed up some ordering