Switched type of ch to unsigned char to avoid cast