Replace mod operations with bitwise AND where possible