cleanup build process and add extra permissions check