recursive function mostly working, failing test