fixed some bugs, added permissions to database