complete algoritm

use oop style