Made a class so there are less locals being passed around. Updated docs.