Refactor the credentials code.