simpler implementation of the previous commit