moved mem declaration further up