moved variables and added additional comments