extended a lot of the for and if loops