rewrote my own sign-extend chain of algorithms