improved filter pattern
copy and mod cpp to c
add c support