added validity checking