private boolean tryInsertIntoChain(final int chainNumber, long key) {
    int chainDisplacement = primaryIndex.getChainDisplacement(chainNumber);

    //try to store record in main bucket
    int pageToStore;
    final int keySignature;

    if (chainDisplacement > 253) {
      return storeRecordInMainBucket(chainNumber, key);
    } else {
      int chainSignature = primaryIndex.getChainSignature(chainNumber);
      keySignature = LinearHashingTableHelper.calculateSignature(key);
      if (keySignature < chainSignature) {
        moveLargestRecordToRecordPool(chainNumber, (byte) chainSignature);
        final boolean result = storeRecordInMainBucket(chainNumber, key);
        storeRecordFromRecordPool();
        return result;
      } else if (keySignature == chainSignature) {
        recordPool.add(key);
        size--;
        moveLargestRecordToRecordPool(chainNumber, (byte) chainSignature);
        Bucket bucket = file.get(chainNumber);

        primaryIndex.updateSignature(chainNumber, bucket.keys, bucket.size);

        storeRecordFromRecordPool();
        return true;
      } else {
        if (chainDisplacement == 253) {
          //allocate new page
          return allocateNewPageAndStore(chainNumber, chainNumber, key, true);

        } else {
          pageToStore = findNextPageInChain(chainNumber, chainDisplacement);
        }
      }
    }

    //try to store in overflow bucket chain
    while (true) {

      int realPosInSecondaryIndex = pageIndicator.getRealPosInSecondaryIndex(pageToStore);
      chainDisplacement = secondaryIndex.getChainDisplacement(realPosInSecondaryIndex);

      if (chainDisplacement > 253) {
        return storeRecordInOverflowBucket(pageToStore, key);
      } else {
        int chainSignature = secondaryIndex.getChainSignature(realPosInSecondaryIndex);
        if (keySignature < chainSignature) {
          moveLargestRecordToRecordPool(pageToStore, (byte) chainSignature);
          final boolean result = storeRecordInOverflowBucket(pageToStore, key);
          storeRecordFromRecordPool();
          return result;
        } else if (keySignature == chainSignature) {
          recordPool.add(key);
          size--;
          moveLargestRecordToRecordPool(pageToStore, (byte) chainSignature);
          Bucket bucket = file.get(pageToStore);

          secondaryIndex.updateSignature(realPosInSecondaryIndex, bucket.keys, bucket.size);

          storeRecordFromRecordPool();
          return true;
        } else {
          if (chainDisplacement == 253) {
            //allocate new page
            return allocateNewPageAndStore(chainNumber, pageToStore, key, false);
          } else {
            pageToStore = findNextPageInChain(chainNumber, chainDisplacement);
          }
        }
      }
    }
  }