Modify authenticate function