improved file path validation and error handling