Refactor getRoles function