working on checking algorithm