Remove redundant NULL checks. Patch by Ragnor.
Remove redundant type casts. Patch by Ragnor.
Avoid casting function pointers. Patch by Ragnor.