duplicated code and minor patches

Signed-off-by: Fabien Crassat <fabien@crassat.com>