Adding malloc checks