well, that took embarrasingly long to finish. I fixed the proble where if the key can be found overlappingly i.e target = aaa key = aa