main method. Input reading & output writing