More generic solution