remove a few unused variable, and add casts to avoid warnings