Remove an unused function.
Remove some dead code and perform a mild refactoring of the other parts.