Fixed main issues, supports heavy recursion