Some more changes to the permissions code. Was returning wrong set of users.