extract repeated code to checkactive subroutine