improved input check