Refactoring authentication framework