Refactoring and added support for role based API auth