fixed it by moving it to a latter part in the code.
But the correction is definitely a bit too aggressive. this was the function I currently used to correct it: