Rework to a more general solution