Fixed few coverity issues like invalid boxing unboxing issues, resource leaks, null dereferences