Fixed some logical errors in malloc