added some of the code into main