fixed segfaults
fixed warnings of malloc redefined