Malloc

add malloc, fix minor errors and bugs