Matt's circle detection code