Added mb_detect_encoding protection
Fixed trailing whitespace check