remove cast of malloc(), rename arguments etc.