fix file boundary handling