added permission check (and fix) for Linux