<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _step(self, theme, direction):
 """ Traverse the list in the given direction and return the next theme """

        if not self.themes:
            self.reload()

        # Try to find the starting index
        key = (theme.source, theme.name)
        for i, val in enumerate(self.themes):
            if (val.source, val.name) == key:
                index = i
                break
        else:
            # If the theme was set from a custom source it might
            # not be a part of the list returned by list_themes().
            self.themes.insert(0, theme)
            index = 0

        index = (index + direction) % len(self.themes)
        new_theme = self.themes[index]
        return new_theme