tested algorithm for checking numbers