ok, now it works for the base case but fails on bad input