cleanup PR590, squash and add perm check, iss #504

thanks jj0hns0n