corrected code for invalid->valid location