moved variables to the top