Full rewrite: bye bye malloc and company