Refactored to be inline with RFC2810-RFC2813 series of RFCs instead of RFC1459.