i think im close to getting this algorithm right.