moved variables to top