added malloc checks, inserted free functions. works on minix