Removed memory errors in code, requires a lot of deletes. It would be better to pass the array rather than create the array in the function. I will plan on changing that in future versions