kind of working version need to check the output of the function some more.