moved memalloc out of draw func