Fixed malloc casting and list copying