Fixed some permissions bugs in the code