fix recursion, a little ugly but oh well