moved variables to first usage in code