Make DetectContentType and DetectCharset less redundant.

Cleaned up these methods for readability and to not do extra work.