This function and the one below could be unified by passing a param.