Working with answer, but takes nearly 2 mins to compute, this needs to be refactored