Another couple of queris moved to a function

Signed-off-by: emanuele <emanuele45@gmail.com>
Wrong variable name

Signed-off-by: emanuele <emanuele45@gmail.com>
Couple of comments

Signed-off-by: emanuele <emanuele45@gmail.com>