refix buggy previous merge by reintroducing changes from c24a04d3