Updated to use a class

Also added some extra caching to some functions