Fix file size type and add extra error checking.