Refactor create role function.