fix unsafe recursion
refac a bit