reimplement with functional-php library