Ok, fixed the bug. Turned out that I was using inconsistent orderings of random variables in different parts of the code.