bug fixing for checking valid