clean up the type- and length-setting logic