refactoring: cleaned up the check() function