implemented memory allocation