added check if file is readable in the function