moved things around to organize and added constructor and destructor