Added recursion
added algorithm4, bumped everything in algorithm2 into a separate function