Fixed the problem by doing proper allocation.