changed memory allocation to use myalloc