added some protections agains overflow in controle sequences and memory overflow