correcting variable scope