Made functions inline, fixed error where i is assumed to be smaller than j, adding recursive (not working with cache yet)

Apparently i can be smaller than j, so I added handling that case.
Add recursive version, was verified to be working, still working on
getting the caching to working with recursion