more simple algorithm