actually build fix... becuse I can't read that res_pos and rest_pos are different, and remove premature optimization and mallocs