--- Quote Start ---
I would not attribute this to programming. Programming is kind of binary. It either works or it doesn't. It doesn't program the board differently some times.
If possible, I'd add Signaltap to the design to see how it's running in hardware. Maybe you can capture signals when the design is not behaving the way you intend to help figure out why.
Have you simulated this design in, say, ModelSim?
--- Quote End ---
No I haven't simulated the design there. the reason that I think it's because of the programming is that I'm literally running the exact same design on a board without changing any file, input, etc.