checking algorithm