all coded but takes a very long time to run