made input foolproof (avoiding segfaults) even when violating all rules