fixed bug with validity checking