fix bugs in insert-casts