moved confusing vars to where thye are used