Inside algorithm