Refactor determining whether application is running or not