moved var so it's in the correct scope