close method added to avoid corrupted output.