Fixed count issue on allocating memory