Changed input and output to arguments. Some other cleanup.