Ouput to the same format as input.
Refactored