added entry size check and a couple of fcloses