And where is the code that invokes run_epoch?
If you don’t provide (a possibly simplified version of) complete executable code, I really don’t see the point in starting to debug the rest of your code, because the bug may be hiding in the part of the code that you did not provide.
So, please, provide a complete set of executable code (ideally, minimized to remove extraneous stuff) that exhibits the behaviour that you want to address.