refactor: move checking code into a check() function