new and modified algo