Added check for mb_detect_encoding(), fixed reference issue