fixed several input and output bugs