The problem seems to be in how python handles lists. Sequence is a list. The program runs through the first branch fine. However after returning to the root, it doesn't use the parents sequence but the last time sequence was updated. Editing the code, to call recursions only with sequence.copy() fixed my issues.