Fixed #1 (previous commit). This tries a DRYed version.