Optimized undefined behaviour
Fixed sign mismatch
Fixed intermediate sign mismatch
Fixed intermediate sign mismatch