Moved legacy mode code to a separate file

This will make it easier to remove when it is no longer needed.