refactor algorithm of check move