refactor to just one check function