wrote most of the malloc function