sketched final method of algorithm