fix ctype size calculation and off-by-one error in stack handling
more tests