core: refactor check for valid pid