Some changes in the existing code have been also made to avoid code duplication and fix some issues. Co-authored-by: Cazals Mathias <mathiascazals@users.noreply.github.com>