Refactored authenticate methods. Added 2 functions. Pne for key, one for headers.