Function works...

...but it is very slow now! We will need to speed this up considerably.