plug some modifications according to comments but keeping the initial scope