move early declaration of temp variables to where used