Latest commit contains an improvement to reduce the complexity which is now O(n)