ENH: functional version, tests updated.