optimize code of isalive