SED from Cube code

Made a pull request while I work on this in case you have comments.
Put the `return table` statement from here and from the next `elif` clause at the end of the function outside the `if` statement.