Added stop command and closed file at end