rewrote validation code