Separated the toafill process and refactored.
The file pointer pointed an illegal value.