refactor head recursion reduction