Only accept (write to the input) valid value

These changes fix the bug #177.