work out the end of the file properly