Add a default trim call and cleanup trim code significantly.
Fix a bug whereby casts to uint8 or int8 would return an incorrect result