move memory allocation to main