Remove duplicated codes and clean functions

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