updated function to work. will add comments later