templated extract function and smaller size type to make bitstream generally smaller