Some fixes for a completely broken function...

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