Fixed recursion

Hackish, uses global variables :(