Remove unused variables and add casts where needed to prevent compiler warnings