Fixed a few bugs having to do with recursion breaking the program

Still may be a few problems with huge images. Need to look into it