Fix CID 1135051
Fix CID 1135066
Fix CID 1212090
Fix CID 1212091 and refactor check_bytes