simplify the code d3756ccd7c and 516587ed47