Fix permission issues and a few other bugs.