Fixed memory getting overwritten