Fixed recursive function call
Added test to check output
Added some pruning