removing some duplicated code, commented the code
add void *inp, *out to function calls, and improve the documentation