revised if-statements to allow recursion