improved file permission checks