Make sure to handle end and close properly.