Switched form recursive to iterative approach. This works but is hacky.