recursive
need refactorate for iterative solution