added Validity class and modified isValid accordingly