Switched from an iterative approach to a functional approach