Move app state checker into a function