Updated exportCategories.php 

fixed recursion and split code up into seperate methods.