changed valid check with better one