Input protection; add logic fix