basic algorithm written. Need to convert it to a recursive for it to work.
first attempt to add recursion. Yet to be tested/debugged.