implemented logic for file input and output