fix head recursion and add test case