finished recursive algorithm stuff.