New changes, main algorithm, may need polish