Added full algorithm