expansion of python functional implementation