Reformatted code into a class for better modularity.