Finally finding the solution to a bug on which I was working for 3 hours